<?php
/**
 * @package    indie-bookstore
 * @subpackage bookstore
 * @author David Neimeyer davidneimeyer@gmail.com
 * administrator/components/com_bookstore/views/locator/view.html.php
 * @link http://indie-bookstore.googlecode.com/
 * @license    GNU/GPL
 * 
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view');

/**
 * HTML View for locator sub component
 *
 */
class BookstoreViewLocator extends JView
{
	function display($tpl = null)
	{
		global $mainframe, $option;
		
		if($this->getLayout() == 'form') {
			//var_dump('switch');
			$this->_displayForm($tpl);
			return;
		}
		
		// Set toolbar items for the page
		JToolBarHelper::title(   JText::_( 'Bookstore Product Locator' ), 'generic.png' );
		JToolBarHelper::deleteList();
		JToolBarHelper::editListX();
		JToolBarHelper::addNewX();
		
		$db		=& JFactory::getDBO();
		$uri	=& JFactory::getURI();

		$filter_id		= $mainframe->getUserStateFromRequest( $option.'a.id',		'a.id',		0,				'int' );
		$filter_title		= $mainframe->getUserStateFromRequest( $option.'a.title',		'a.title',		0,				'string' );
		$filter_order		= $mainframe->getUserStateFromRequest( $option.'filter_order',		'filter_order',		'a.ordering',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		$search				= $mainframe->getUserStateFromRequest( $option.'search',			'search',			'',				'string' );
		$search				= JString::strtolower( $search );

		// Get data from the model
		$items		= & $this->get( 'Data');
		$total		= & $this->get( 'Total');
		$pagination = & $this->get( 'Pagination' );

		// build list of categories
		$javascript 	= 'onchange="document.adminForm.submit();"';
		$lists['catid'] = JHTML::_('list.category',  'filter_catid', $option, intval( $filter_catid ), $javascript );

		// state filter
		$lists['state']	= JHTML::_('grid.state',  $filter_state );

		// table ordering
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;
		$lists['title'] = $filter_title;
		$lists['id'] = $filter_id;

		// search filter
		$lists['search']= $search;

		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('lists',		$lists);
		$this->assignRef('items',		$items);
		$this->assignRef('pagination',	$pagination);
		$this->assignRef('request_url',	$uri->toString());

		parent::display($tpl);
		
	}//end display method
	
	function _displayForm($tpl){
		global $mainframe, $option;
		
		$model	=& $this->getModel();
		$id		= JRequest::getVar( 'id', '', 'get', 'int' );
		if((int)$id < 1){
			// new locale creation
			$text = JText::_( 'New' );
			//TODO: set some default values
			$locale = '';
						
		}else{
			//old, edit locale
			$text = JText::_( 'Edit' );
			
			$locale =& $this->get('Data');	
		}
		
		JToolBarHelper::title(   JText::_( 'Bookstore Product Locator' ).': <small><small>[ ' . $text.' ]</small></small>' );
		JToolBarHelper::save();
		if ($isNew)  {
			JToolBarHelper::cancel();
		} else {
			// for existing items the button is renamed `close`
			JToolBarHelper::cancel( 'cancel', 'Close' );
		}
		JToolBarHelper::help( 'screen.bookstore.edit' );

		$db		=& JFactory::getDBO();
		$uri	=& JFactory::getURI();

		$filter_state		= $mainframe->getUserStateFromRequest( $option.'filter_state',		'filter_state',		'',				'word' );
		$filter_catid		= $mainframe->getUserStateFromRequest( $option.'filter_catid',		'filter_catid',		0,				'int' );
		$filter_order		= $mainframe->getUserStateFromRequest( $option.'filter_order',		'filter_order',		'a.ordering',	'cmd' );
		$filter_order_Dir	= $mainframe->getUserStateFromRequest( $option.'filter_order_Dir',	'filter_order_Dir',	'',				'word' );
		$search				= $mainframe->getUserStateFromRequest( $option.'search',			'search',			'',				'string' );
		$search				= JString::strtolower( $search );
		// Get data from the model
		$total		= & $this->get( 'Total');
		$pagination = & $this->get( 'Pagination' );
		$maps		= & $this->get( 'Maps' );
		// build list of categories
		$javascript 	= 'onchange="document.adminForm.submit();"';
		$lists['catid'] = JHTML::_('list.category',  'filter_catid', $option, intval( $filter_catid ), $javascript );

		// state filter
		$lists['state']	= JHTML::_('grid.state',  $filter_state );

		// table ordering
		$lists['order_Dir'] = $filter_order_Dir;
		$lists['order'] = $filter_order;

		// search filter
		$lists['search']= $search;

		$this->assignRef('user',		JFactory::getUser());
		$this->assignRef('locale',		$locale);
		$this->assignRef('maps',		$maps);
		$this->assignRef('pagination',	$pagination);
		$this->assignRef('request_url',	$uri->toString());
		parent::display($tpl);
	
	}
}
?>